import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    username: window.localStorage.getItem('username'),
    token: window.localStorage.getItem('token')
  },
  mutations: {
    setUserName (state, username) {
      state.username = username
      window.localStorage.setItem('username', username)
    },
    setToken (state, token) {
      state.token = token
      window.localStorage.setItem('token', token)
    },

    removeUserName (state) {
      state.username = ''
      window.localStorage.removeItem('username')
    },
    removeToken (state) {
      state.token = ''
      window.localStorage.removeItem('token')
    }
  }
})

export default store
